﻿namespace Example
{
    using System;
    using Cavity;
    using Xunit;

    public sealed class HttpClientFacts
    {
        [Fact]
        public void ctor_Uri()
        {
            Assert.NotNull(new HttpClient(new Uri("http://example.com/")));
        }

        [Fact]
        public void ctor_UriFtp()
        {
            Assert.Throws<ArgumentOutOfRangeException>(() => new HttpClient(new Uri("ftp://example.com/")));
        }

        [Fact]
        public void ctor_UriNull()
        {
            Assert.Throws<ArgumentNullException>(() => new HttpClient(null as Uri));
        }

        [Fact]
        public void ctor_UriRelative()
        {
            Assert.Throws<ArgumentOutOfRangeException>(() => new HttpClient(new Uri("/", UriKind.Relative)));
        }

        [Fact]
        public void ctor_string()
        {
            Assert.NotNull(new HttpClient("http://example.com/"));
        }

        [Fact]
        public void ctor_stringFtp()
        {
            Assert.Throws<ArgumentOutOfRangeException>(() => new HttpClient("ftp://example.com/"));
        }

        [Fact]
        public void ctor_stringNull()
        {
            Assert.Throws<ArgumentNullException>(() => new HttpClient(null as string));
        }

        [Fact]
        public void ctor_stringRelative()
        {
            Assert.Throws<ArgumentOutOfRangeException>(() => new HttpClient("/"));
        }

        [Fact]
        public void prop_Uri_get()
        {
            var expected = new Uri("http://example.com/");
            var actual = new HttpClient(expected).Uri;

            Assert.Same(expected, actual);
        }

        [Fact]
        public void prop_Uri_set()
        {
            var obj = new HttpClient(new Uri("http://example.com/"));

            var expected = new Uri("http://example.net/");
            obj.Uri = expected;
            var actual = obj.Uri;

            Assert.Same(expected, actual);
        }

        [Fact]
        public void prop_Uri_setFtp()
        {
            var obj = new HttpClient(new Uri("http://example.com/"));

            Assert.Throws<ArgumentOutOfRangeException>(() => obj.Uri = new Uri("ftp://example.com/"));
        }

        [Fact]
        public void prop_Uri_setNull()
        {
            var obj = new HttpClient(new Uri("http://example.com/"));

            Assert.Throws<ArgumentNullException>(() => obj.Uri = null as Uri);
        }

        [Fact]
        public void prop_Uri_setRelative()
        {
            var obj = new HttpClient(new Uri("http://example.com/"));

            Assert.Throws<ArgumentOutOfRangeException>(() => obj.Uri = new Uri("/", UriKind.Relative));
        }

        [Fact]
        public void type_definition()
        {
            Assert.True(new TypeExpectations<HttpClient>()
                            .DerivesFrom<object>()
                            .IsConcreteClass()
                            .IsSealed()
                            .NoDefaultConstructor()
                            .IsNotDecorated()
                            .Result);
        }
    }
}